package cn.demoncat.util.lang.entity.report;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import cn.demoncat.util.mybatis.base.BaseReportEntity;

/**
 * 报表时间
 * 
 * @author 延晓磊
 *
 * @since 2019年12月11日
 */
public class ReportTime {

	// 统计时间-年
	private Integer year;
	// 统计时间-月
	private Integer month;
	// 统计时间-日
	private Integer day;
	// 统计时间-时
	private Integer hour;

	public ReportTime() {
		super();
	}

	public ReportTime(Integer year, Integer month, Integer day, Integer hour) {
		super();
		this.year = year;
		this.month = month;
		this.day = day;
		this.hour = hour;
	}
	
	public ReportTime(LocalDateTime date) {
		super();
		this.year = date.getYear();
		this.month = date.getMonthValue();
		this.day = date.getDayOfMonth();
		this.hour = date.getHour();
	}

	public ReportTime(LocalDate date) {
		super();
		this.year = date.getYear();
		this.month = date.getMonthValue();
		this.day = date.getDayOfMonth();
	}
	
	public ReportTime(BaseReportEntity<?, ?> report) {
		super();
		this.year = report.getYear();
		this.month = report.getMonth();
		this.day = report.getDay();
		this.hour = report.getHour();
	}
	
	public ReportTime(ReportParam param) {
		this(param.getYear(), param.getMonth(), param.getDay(), param.getHour());
	}

	/**
	 * 整合图表查询参数
	 * 
	 * @param condition	查询参数
	 * 
	 * @return {查询参数，y,m,d,h}
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年12月11日
	 */
	public Map<String, Object> getParams(Map<String, Object> condition){
		// 参数校验
		if (condition == null) {
			condition = new HashMap<>();
		}
		// 整合查询条件
		condition.put("year", this.getYear());
		condition.put("month", this.getMonth());
		condition.put("day", this.getDay());
		condition.put("hour", this.getHour());
		return condition;
	}
	
	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public Integer getMonth() {
		return month;
	}

	public void setMonth(Integer month) {
		this.month = month;
	}

	public Integer getDay() {
		return day;
	}

	public void setDay(Integer day) {
		this.day = day;
	}

	public Integer getHour() {
		return hour;
	}

	public void setHour(Integer hour) {
		this.hour = hour;
	}

}
